#include <windows.h>
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam){
	DWORD pid = 0;
	HANDLE hProcess;
	DWORD dwResult;
	LRESULT lResult = SendMessageTimeout(hwnd, WM_QUERYENDSESSION, 0, ENDSESSION_LOGOFF, SMTO_ABORTIFHUNG, 2000, &dwResult);
	if( lResult ){
		lResult = SendMessageTimeout(hwnd, WM_ENDSESSION, TRUE, ENDSESSION_LOGOFF, SMTO_ABORTIFHUNG, 2000, &dwResult);
	}else{
		GetWindowThreadProcessId( hwnd, &pid );
		hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
		TerminateProcess(hProcess, 0);
	}
	return TRUE;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){
	EnumWindows(EnumWindowsProc, 0);
	ExitWindowsEx(EWX_LOGOFF , 0);
	return 0;
}
